package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.service.ArticleService;
import com.tarena.lbs.pojo.content.dto.ArticleContentDTO;
import com.tarena.lbs.pojo.content.param.ArticleCategoryParam;
import com.tarena.lbs.pojo.content.query.ArticleQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tarena.lbs.base.protocol.model.Result;

import java.util.HashSet;

@Slf4j
@RestController
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/admin/content/article/list")
    public Result<PageResult<ArticleContentDTO>> queryList(ArticleQuery query) throws BusinessException {
        log.debug("查询文章列表接口入参 ArticleQuery:{} ",query);
        PageResult<ArticleContentDTO> pageResult = articleService.queryList(query);
        return new Result<>(pageResult);
    }

    @PostMapping("/admin/content/article/insert")
    public Result<Void> addArticle(ArticleCategoryParam param) throws  BusinessException{
        articleService.addArticle(param);
        return Result.success();
    }

    @GetMapping("/admin/content/article/getArticleLabel")
    public Result<HashSet<String>> getArticleLables(ArticleQuery query) throws BusinessException{
        log.debug("手机小程序端获取文章信息参数 ArticleQuery:{}",query);
        HashSet<String> articleLables = articleService.getArticleLables(query);
        return new Result<>(articleLables);
    }

    @GetMapping("/admin/content/article/get")
    public Result<ArticleContentDTO> contentDetail(String id) throws BusinessException{
        log.debug("获取文章详细信息入参 id={}",id);
        ArticleContentDTO dto = articleService.getArticleDetail(id);
        return new Result<>(dto);
    }

}
